package com.lyh.ai.controller;

import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.image.ImageOptions;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
import org.springframework.ai.zhipuai.ZhiPuAiImageOptions;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class ImageController {

    private final ZhiPuAiImageModel zhiPuAiImageModel;

    @Autowired
    public ImageController(ZhiPuAiImageModel zhiPuAiImageModel) {
        this.zhiPuAiImageModel = zhiPuAiImageModel;
    }

    @GetMapping("image1")
    public String image1(@RequestParam("message") String message) {
        // 默认模型为 cogview-3
        ImageResponse imageResponse = zhiPuAiImageModel.call(
                new ImagePrompt(
                        message
                ));
        return imageResponse.getResult().getOutput().toString();
    }


    @GetMapping("image2")
    public String image2(@RequestParam("message") String message) {
        ImageResponse imageResponse = zhiPuAiImageModel.call(
                new ImagePrompt(
                        message,
                        ZhiPuAiImageOptions.builder()
                                .withModel("cogview-3")
                                .build()
                ));
        return imageResponse.getResult().getOutput().toString();
    }


}
